import axios from "@/utils/axios";

// 获取推荐歌单
const getRecMusic = () =>
  axios.get(`/personalized`, {
    params: {
      limit: 6,
    },
  });

// 推荐新音乐
const getRecNewMusic = () =>
  axios.get(`/personalized/newsong`, {
    params: {
      limit: 10,
    },
  });

// 获取所有榜单
const getAllSheet = () => axios.get(`/toplist`);

// 获取歌单详情
const getPlayListDetail = (id: number) =>
  axios.get(`/playlist/detail`, { params: { id } });

// 获取歌单所有歌曲
const getPlayListAllMusic = ({
  id,
  limit = 10,
}: {
  id: number;
  limit?: number;
}) => {
  return axios.get(`/playlist/track/all`, {
    params: {
      id,
      limit,
    },
  });
};

// 热门搜索 简略
const getSimpleHotSearch = () => axios.get(`/search/hot`);

// 获取音乐详情
const getSongDetail = (ids: string) =>
  axios.get(`/song/detail`, { params: { ids } });

// 获取音乐 url
const getSongUrl = (id: string) => axios.get(`/song/url`, { params: { id } });

// 获取音乐 url 新版
// level: 播放音质等级, 分为 standard => 标准,higher => 较高, exhigh=>极高, lossless=>无损, hires=>Hi-Res
const getSongUrlNew = (id: string, level = "lossless") =>
  axios.get(`/song/url/v1`, { params: { id, level } });

// 获取歌词
const getSongLrc = (id: number) => axios.get(`/lyric`, { params: { id } });

// 获取搜索
const searchSong = (keywords: string) =>
  axios.get("/search/suggest", { params: { keywords, type: "mobile" } });

// 多重匹配 获取 歌手和歌单
const getPlaylistAndSing = (keywords: string) =>
  axios.get("/search/multimatch", { params: { keywords } });

// 更全搜索 type: 搜索类型；默认为 1 即单曲 , 取值意义 : 1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单, 1002: 用户, 1004: MV, 1006: 歌词, 1009: 电台, 1014: 视频, 1018:综合, 2000:声音(搜索声音返回字段格式会不一样)
const getCloudSearch = ({
  keywords,
  limit = 10,
}: {
  keywords: string;
  limit?: number;
}) => axios.get("/cloudsearch", { params: { keywords, limit } });

export {
  getRecMusic,
  getRecNewMusic,
  getAllSheet,
  getPlayListAllMusic,
  getSimpleHotSearch,
  getPlayListDetail,
  getSongDetail,
  getSongUrl,
  getSongUrlNew,
  getSongLrc,
  searchSong,
  getPlaylistAndSing,
  getCloudSearch,
};
